package com.itheima.bos.dao.impl;

import com.itheima.bos.dao.IFunctionDao;
import com.itheima.bos.dao.base.IBaseDaoImpl;
import com.itheima.bos.domain.Function;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Mr.King on 2017/3/16.
 */
@Repository
public class FunctionDaoImpl extends IBaseDaoImpl<Function> implements IFunctionDao {
    @Override
    public List<Function> findAllMenu() {
        String hql = "from com.itheima.bos.domain.Function f Where f.generatemenu = '1' order by f.zindex desc";
        return (List<Function>) this.getHibernateTemplate().find(hql);
    }

    @Override
    //根据用户id查询权限菜单数据
    public List<Function> findMenu(String userid) {
        String hql = "select  distinct f from Function f left outer join fetch " +
                "f.roles r left outer join fetch r.users u where u.id = ?" +
                " and f.generatemenu = '1' order by f.zindex desc ";
        return (List<Function>) this.getHibernateTemplate().find(hql, userid);
    }
}
